<div class="easyui-layout" data-options="fit:true,border:false">
	<div data-options="region:'west',split:true" style="width: 150px">
		<div id="dl_allbutton" title="{$buttonlist}"> </div>
	</div>
	<div data-options="region:'center'">
 		<table id="dg_pagebutton" class="easyui-datagrid" 
				data-options="
					singleSelect: true,
					method:'get',
					fit:true,
					border:false
				">
			<thead>
				<tr>
					<th data-options="field:'btn_id',width:60">{$btn_id}</th>
					<th data-options="field:'btn_name',width:100">{$btn_name}</th>
					<th data-options="field:'handler',editor:'text',width:200">{$handler}</th>
					<th data-options="field:'sort',editor:'text',width:40">{$sort}</th>
				</tr>
			</thead>
		</table>
	</div>
</div>
<script type="text/javascript">
	function loadButtonlist (node, type) {
		var url = '/OA/Admin/SysModule/getButtonlist?mid=' + node.id + '&type=' + type;
		var $dl = $('#dl_allbutton');
		$dl.datalist({
			url: url,
            method: 'get',
            border: false,
            onDblClickRow: function (index, row) {
            	var $dg = $('#dg_pagebutton');
            	$dg.datagrid('appendRow',{btn_id: row.id, btn_name: row.text});
            	$dl.datalist('deleteRow', index);
            }
		})
	}
	function loadPageButton (node) {
		var url = '/OA/Admin/SysModule/getPageButtonlist?mid=' + node.id;
		var $dg = $('#dg_pagebutton');
		$dg.datagrid({
			singleSelect: true,
			method:'get',
			fit:true,
			border:false,
			url: url,
			onClickRow: onClickRow,
            onDblClickRow: function (index, row) {
            	var $dl = $('#dl_allbutton');
            	$dl.datalist('appendRow',{id: row.btn_id, text: row.btn_name});
            	$dg.datagrid('deleteRow', index);
            }
		})
	}
	function savePageButton (mid) {
		var dg = $('#dg_pagebutton');
		if (endEditing(dg)){
			var $rows = {};
			var inserted = dg.datagrid('getChanges', "inserted"); 
            var updated = dg.datagrid('getChanges', "updated"); 
            var deleted = dg.datagrid('getChanges', "deleted"); 
            if(inserted.length>0) $rows['inserted'] = JSON.stringify(inserted);
            if(updated.length>0) $rows['updated'] = JSON.stringify(updated);
            if(deleted.length>0) $rows['deleted'] = JSON.stringify(deleted);
			if($rows.inserted==undefined && $rows.updated==undefined && $rows.deleted==undefined) return;
			$.ajax({
                type: 'POST',
                datatype: 'json',
                url: '/OA/Admin/SysModule/updatePageButton?mid=' + mid,
                data: $rows,
                success: function (data) {
					$.messager.alert(TIP_MSG.TITLE, data.statusmessage,'info');
                }
            });
		}
	}
</script>